package com.lsj.Util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class JedisConnectionFactory {
    private static final JedisPool jedisPool;
    static {
        //1.配置连接池
        JedisPoolConfig poolconfig = new JedisPoolConfig();
        //1.1设置最大连接数
        poolconfig.setMaxTotal(8);
        //1.2设置最大空闲连接数
        poolconfig.setMaxIdle(8);
        //1.3设置最小空闲连接数
        poolconfig.setMinIdle(0);
        //1.4设置连接超时时间
        poolconfig.setMaxWaitMillis(1000);
        //2.创建连接池对象
        jedisPool = new JedisPool(poolconfig, "127.0.0.1", 6379,1000);
    }
    //3.获取连接方法
    public static Jedis getJedis() {
        return jedisPool.getResource();
    }
}
